package com.k.base.jdk.sort.list;

import java.util.*;

public class PersonTest {
    public static void main(String[] args) {
        List<Person> personList = getData();
        System.out.println(personList);

        Collections.sort(personList, new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
               // return o2.getBirth().compareTo(o1.getBirth());
                return o2.getAge()-o1.getAge();
            }
        });
        System.out.println(personList);
    }

    private static List<Person> getData() {
        List<Person> personList = new ArrayList<>();
        for(int i=0;i<10;i++){
            Date now = new Date();
            Calendar cal = Calendar.getInstance();
            cal.setTime(now);
            cal.add(Calendar.DATE, i);
            Person p = new Person("1"+i,"tom"+i,20+i,cal.getTime());
            personList.add(p);
        }
        return personList;
    }
}
